if __name__ == "__main__":
    import os
    import sys
    import django

    ###1、将django根目录加入到环境变量中
    # 当前文件所在目录
    current_path = os.path.dirname(os.path.realpath(__file__))
    # django项目的根目录
    django_root_path = os.path.dirname(current_path)
    # 将django项目的根目录加入到当前的环境变量中
    sys.path.insert(0, django_root_path)
    ####2、引入django环境
    # 设置DJANGO_SETTINGS_MODULE环境变量
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "scheduler_project.settings")
    # 确保Django环境被正确设置
    django.setup()
from scheduler_package.logger import scheduler_logger as logger
from bases.base_scheduler import RunBlockScheduler, RunBackgroundScheduler


# 独占进程运行的调度器
def run_block_scheduler():
    try:
        obj = RunBlockScheduler()
        obj.start()
    except Exception as e:
        logger.exception(f"阻塞式调度器启动失败，{e}")


# 后台运行的调度器
def run_background_scheduler():
    try:
        obj = RunBackgroundScheduler()
        obj.start()
    except Exception as e:
        logger.exception(f"后台式调度器启动失败，{e}")


if __name__ == "__main__":
    run_block_scheduler()
